/**
 * ...
 * @author Hatshepsout
 */

function ElementEditorFiche(){}

ElementEditorFiche.prototype._currentElement 			= null;
ElementEditorFiche.prototype._resizeXButton 			= null;
ElementEditorFiche.prototype._resizeYButton 			= null;
ElementEditorFiche.prototype._resizeXYButton 			= null;
ElementEditorFiche.prototype._contrastButton 			= null;
ElementEditorFiche.prototype._brightnessButton 			= null;
ElementEditorFiche.prototype._alphaButton 				= null;
//ElementEditorFiche.prototype._borderButton 				= null;
//ElementEditorFiche.prototype._backgroundButton 			= null;
//ElementEditorFiche.prototype._colorPickerBorder 		= null;
//ElementEditorFiche.prototype._colorPickerBackground 	= null;
ElementEditorFiche.prototype._clipLeftButton 			= null;
ElementEditorFiche.prototype._clipRightButton 			= null;
ElementEditorFiche.prototype._clipBottomButton 			= null;
ElementEditorFiche.prototype._clipTopButton 			= null;

ElementEditorFiche.prototype.setCurrentElement = function(value)
{
	this._currentElement = value;
	this.actualizeCheckboxes();
};

ElementEditorFiche.prototype.actualizeCheckboxes = function()
{
	//this._borderButton.checked = "";
	//this._backgroundButton.checked = "";
	this._contrastButton.value = 0;
	this._brightnessButton.value = 0;
	this._alphaButton.value = 1;
	this._clipBottomButton.checked = "";
	this._clipLeftButton.checked = "";
	this._clipRightButton.checked = "";
	this._clipTopButton.checked = "";
	this._contrastButton.disabled = "disabled";
	this._brightnessButton.disabled = "disabled";
	this._alphaButton.disabled = "disabled";
	
	if( this._currentElement == null )
		return;
		
	if( this._currentElement.allowFilters == true )
	{
		this._contrastButton.removeAttribute("disabled");
		this._brightnessButton.removeAttribute("disabled");
		this._alphaButton.removeAttribute("disabled");
	}
		
	this._contrastButton.value = this._currentElement.contrast;
	this._brightnessButton.value = this._currentElement.brightness;
	this._alphaButton.value = this._currentElement.alpha;
	
	//if( this._currentElement.border == true )
	//{
		//this._borderButton.checked = "checked";
	//}	
	//
	//if( this._currentElement.background == true )
	//{
		//this._backgroundButton.checked = "checked";
	//}
	//
	if( this._currentElement.clipTop == true )
	{
		this._clipTopButton.checked = "checked";
	}
	
	if( this._currentElement.clipLeft == true )
	{
		this._clipLeftButton.checked = "checked";
	}
	
	if( this._currentElement.clipRight == true )
	{
		this._clipRightButton.checked = "checked";
	}
	
	if( this._currentElement.clipBottom == true )
	{
		this._clipBottomButton.checked = "checked";
	}
	
	//this._colorPickerBackground.setColor(this._currentElement.backgroundColor);
	//this._colorPickerBorder.setColor(this._currentElement.borderColor);
};

ElementEditorFiche.prototype.init = function()
{
	//this._colorPickerBorder = new ColorPicker();
	//this._colorPickerBackground = new ColorPicker();
	this._clipLeftButton = document.getElementById("clipLeft");
	this._clipTopButton = document.getElementById("clipTop");
	this._clipBottomButton = document.getElementById("clipBottom");
	this._clipRightButton = document.getElementById("clipRight");
	this._resizeXButton = document.getElementById("resizeX");
	this._resizeYButton = document.getElementById("resizeY");
	this._resizeXYButton = document.getElementById("resizeXY");
	this._contrastButton = document.getElementById("contrastButton");
	this._brightnessButton = document.getElementById("brightnessButton");
	this._alphaButton = document.getElementById("alphaButton");
	//this._borderButton = document.getElementById("borderButton");
	//this._backgroundButton = document.getElementById("backgroundButton");
	//this._colorPickerBorder.init( document.getElementById("colorPickerContainerBorder"), 146,159 );
	//this._colorPickerBorder.addEventListener( ColorPicker.CHANGE_COLOR_EVENT, this, this._borderEditHandler );
	
	//this._colorPickerBackground.init( document.getElementById("colorPickerContainerBackground"), 146,159 );
	//this._colorPickerBackground.addEventListener( ColorPicker.CHANGE_COLOR_EVENT, this, this._backgroundEditHandler );
	
	var scope = this;
	var callback = function(){
		scope._rightHandler.apply(scope,arguments);
	};
	
	this._contrastButton.onchange = callback;
	this._brightnessButton.onchange = callback;
	this._alphaButton.onchange = callback;
	this._resizeXButton.addEventListener("click",callback);
	this._resizeYButton.addEventListener("click",callback);
	this._resizeXYButton.addEventListener("click",callback);
	//this._borderButton.addEventListener("click",callback);
	//this._backgroundButton.addEventListener("click",callback);
	this._clipBottomButton.addEventListener("click",callback);
	this._clipLeftButton.addEventListener("click",callback);
	this._clipRightButton.addEventListener("click",callback);
	this._clipTopButton.addEventListener("click",callback);
};

//ElementEditorFiche.prototype._borderEditHandler = function(event)
//{
	//if( this._currentElement == null )
		//return;
		//
	//this._currentElement.borderColor = this._colorPickerBorder.getColor();
//};

//ElementEditorFiche.prototype._backgroundEditHandler = function(event)
//{
	//if( this._currentElement == null )
		//return;
		//
	//this._currentElement.backgroundColor = this._colorPickerBackground.getColor();
	//
	//if( this._currentElement.refresh != undefined )
		//this._currentElement.refresh();
//};

ElementEditorFiche.prototype._rightHandler = function(event)
{
	var checked = false;
	
	if( this._currentElement == null )
		return;
		
	checked = event.target.checked;
	
	switch( event.target )
	{
		case this._clipBottomButton		: 	this._currentElement.clipBottom = checked; break;
		case this._clipLeftButton		: 	this._currentElement.clipLeft = checked; break;
		case this._clipRightButton		: 	this._currentElement.clipRight = checked; break;
		case this._clipTopButton		: 	this._currentElement.clipTop = checked; break;
		case this._contrastButton		: 	this._currentElement.setContrast( this._contrastButton.value );  break;
		case this._brightnessButton		: 	this._currentElement.setBrightness( this._brightnessButton.value ); break;
		case this._alphaButton			: 	this._currentElement.setAlpha( this._alphaButton.value ); break;
		//case this._borderButton			: 	this._currentElement.border = checked; break;
		//case this._backgroundButton		: 	this._currentElement.background = checked; break;
		
		case this._resizeXButton:
			if( this._currentElement.resizeByWidth != undefined )
			{
				this._currentElement.resizeByWidth();
			}
			break;
			
		case this._resizeYButton:
			if( this._currentElement.resizeByHeight != undefined )
			{
				this._currentElement.resizeByHeight();
			}
			break;
			
		case this._resizeXYButton:
			if( this._currentElement.resizeByHeight != undefined )
			{
				this._currentElement.fitSize();
			}
			break;
	}
	
	if( this._currentElement.refresh != undefined )
	{
		this._currentElement.refresh();
	}
};

